package com.googlecode.flex_solder.controls  {

  import mx.core.Container;
  import mx.core.UIComponent;
  import mx.core.UITextField;

  /**
   * Class: StatusText
   * This class creates a status bar with three UITextField
   * controls. Any or all of the controls can be updated with text
   * showing the current status of the application.
   */
  public class StatusText extends Container {
    private var _textLines:Array = null;

    private var _leftStatusWidth:Number;
    private var _centerStatusWidth:Number;
    private var _rightStatusWidth:Number;

    private var _statusHeight:Number;
    private var statusX:Number = 0;
    private var statusY:Number = 0;

    private var _leftStatusText:UITextField;
    private var _centerStatusText:UITextField;
    private var _rightStatusText:UITextField;

    private var containerHeight:Number = 0;
    private var containerWidth:Number = 0;

    protected var textHeight:Number;

    public function StatusText() {

    }

    public function setTextAll(leftText:String,
			       centerText:String, 
			       rightText:String):void {
      _leftStatusText.text = leftText;
      _centerStatusText.text = centerText;
      _rightStatusText.text = rightText;
    }



    public function setTextLeft(leftText:String):void {
      _leftStatusText.text = leftText;
    }


    public function setTextCenter(centerText:String):void {
      _centerStatusText.text = centerText;
    }


    public function setTextRight(rightText:String):void {
      _rightStatusText.text = rightText;
    }


    public function initStatusText(leftStatusWth:Number, 
				   centerStatusWth:Number,
				   rightStatusWth:Number,
				   statusHt:Number):void {
      
      leftStatusWidth = leftStatusWth;
      centerStatusWidth = centerStatusWth;
      rightStatusWidth = rightStatusWth;
      statusHeight = statusHt;

      containerHeight = _statusHeight;

      initLeftStatus();
      initCenterStatus();
      initRightStatus();

      this.explicitHeight = containerHeight;
      this.explicitWidth = containerWidth + 10;
      this.explicitMaxWidth = containerWidth + 10;
      this.validateNow();
      trace(this.uid + ' h=' + this.height + ' w=' + this.width);
      trace(getInfo());
    }

    protected function initLeftStatus():void {

      _leftStatusText = new UITextField();

      _leftStatusText.restrict = "";

      if (isNaN(_leftStatusWidth)) {
	_leftStatusWidth = 0;
      }

      _leftStatusText.explicitWidth = _leftStatusWidth;

      if (!isNaN(_statusHeight)) {
	_leftStatusText.explicitHeight = _statusHeight;
      }
      _leftStatusText.x = statusX;
      _leftStatusText.y = statusY;
      this.addChild(_leftStatusText);
      _leftStatusText.validateNow();
      trace('_statusHeight=' + _statusHeight
	    + ' _leftStatusWidth=' + _leftStatusWidth);
      trace('statusY=' + statusY + ' text=' + _leftStatusText.text
	    + ' h=' + _leftStatusText.height
	    + ' w=' + _leftStatusText.width
	    + ' x=' + _leftStatusText.x + ' y=' + _leftStatusText.y);

      statusX += _leftStatusText.width;

      containerWidth += _leftStatusText.width;

    }

    protected function initCenterStatus():void {

      _centerStatusText = new UITextField();

      _centerStatusText.restrict = "";

      if (isNaN(_centerStatusWidth)) {
	_centerStatusWidth = 0;
      }

      _centerStatusText.explicitWidth = _centerStatusWidth;

      if (!isNaN(_statusHeight)) {
	_centerStatusText.explicitHeight = _statusHeight;
      }
      _centerStatusText.x = statusX;
      _centerStatusText.y = statusY;
      this.addChild(_centerStatusText);
      _centerStatusText.validateNow();
      trace('_statusHeight=' + _statusHeight
	    + ' _centerStatusWidth=' + _centerStatusWidth);
      trace('statusY=' + statusY + ' text=' + _centerStatusText.text
	    + ' h=' + _centerStatusText.height
	    + ' w=' + _centerStatusText.width
	    + ' x=' + _centerStatusText.x + ' y=' + _centerStatusText.y);

      statusX += _centerStatusText.width;

      containerWidth += _centerStatusText.width;


    }


    protected function initRightStatus():void {

      _rightStatusText = new UITextField();

      _rightStatusText.restrict = "";

      if (isNaN(_rightStatusWidth)) {
	_rightStatusWidth = 0;
      }

      _rightStatusText.explicitWidth = _rightStatusWidth;

      if (!isNaN(_statusHeight)) {
	_rightStatusText.explicitHeight = _statusHeight;
      }
      _rightStatusText.x = statusX;
      _rightStatusText.y = statusY;
      this.addChild(_rightStatusText);
      _rightStatusText.validateNow();
      trace('_statusHeight=' + _statusHeight
	    + ' _rightStatusWidth=' + _rightStatusWidth);
      trace('statusY=' + statusY + ' text=' + _rightStatusText.text
	    + ' h=' + _rightStatusText.height
	    + ' w=' + _rightStatusText.width
	    + ' x=' + _rightStatusText.x + ' y=' + _rightStatusText.y);

      statusX += _rightStatusText.width;

      containerWidth += _rightStatusText.width;


    }


    public function setComponentSize():void {
      this.setActualSize(getRealWidth(), getRealHeight());      
    }

    public function getRealHeight():Number {
      var realHeight:Number = this.height;
      if (0 == realHeight) {
	realHeight = this.getExplicitOrMeasuredHeight();
      }

      return realHeight;

    }

    public function getRealWidth():Number {
      var realWidth:Number = this.width;
      if (0 == realWidth) {
	realWidth = this.getExplicitOrMeasuredWidth();
      }

      return realWidth;

    }

    public function get statusHeight():Number {
       return _statusHeight;
    }

    [Bindable]
    public function set statusHeight(statusHeight:Number):void {
       _statusHeight = statusHeight;
    }

    public function getInfo():String {
      var controlInfo:String = "";
      controlInfo = this.uid + " x=" + this.x + " y=" + this.y
	+ " eOrmh=" + this.getExplicitOrMeasuredHeight()
	+ " eOrmw=" + this.getExplicitOrMeasuredWidth()
	+ " left.eOrmw=" + _leftStatusText.getExplicitOrMeasuredWidth()
	+ " left.eOrmh=" + _leftStatusText.getExplicitOrMeasuredHeight()
	+ " center.eOrmw=" + _centerStatusText.getExplicitOrMeasuredWidth()
	+ " center.eOrmh=" + _centerStatusText.getExplicitOrMeasuredHeight()
	+ " right.eOrmw=" + _rightStatusText.getExplicitOrMeasuredWidth()
	+ " right.eOrmh=" + _rightStatusText.getExplicitOrMeasuredHeight()

	+ " h=" + this.height
	+ " w=" + this.width
	;
      return controlInfo;
    }

    public function get leftStatusText():UITextField {
       return _leftStatusText;
    }

    [Bindable]
    public function set leftStatusText(leftStatusText:UITextField):void {
       _leftStatusText = leftStatusText;
    }

    public function get centerStatusText():UITextField {
       return _centerStatusText;
    }

    [Bindable]
    public function set centerStatusText(centerStatusText:UITextField):void {
       _centerStatusText = centerStatusText;
    }

    public function get rightStatusText():UITextField {
       return _rightStatusText;
    }

    [Bindable]
    public function set rightStatusText(rightStatusText:UITextField):void {
       _rightStatusText = rightStatusText;
    }

    public function get leftStatusWidth():Number {
       return _leftStatusWidth;
    }

    [Bindable]
    public function set leftStatusWidth(leftStatusWidth:Number):void {
       _leftStatusWidth = leftStatusWidth;
    }

    public function get centerStatusWidth():Number {
       return _centerStatusWidth;
    }

    [Bindable]
    public function set centerStatusWidth(centerStatusWidth:Number):void {
       _centerStatusWidth = centerStatusWidth;
    }

    public function get rightStatusWidth():Number {
       return _rightStatusWidth;
    }

    [Bindable]
    public function set rightStatusWidth(rightStatusWidth:Number):void {
       _rightStatusWidth = rightStatusWidth;
    }
  }
}